// 合并区间
class Solution {
    public:
        vector<vector<int>> merge(vector<vector<int>>& intervals) {
            sort(intervals.begin(), intervals.end());
            vector<vector<int>> res;
            int l = intervals[0][0], r = intervals[0][1];
            for (int i = 1; i < intervals.size(); i++)
            {
                int a = intervals[i][0], b = intervals[i][1];
                // 当区间重叠时合并两个区间
                if (a <= r) r = max(r, b);
                else 
                {
                    // 当区间不重叠时插入
                    res.push_back({l, r});
                    l = a, r = b;
                }
            }
            res.push_back({l, r});
            return res;
        }
    };

// 最大数组合
class Solution {
    public:
        int maxSubArray(vector<int>& nums) {
            int res = -0x3f3f3f3f;
            int pre = 0;
            for (auto e : nums)
            {
                pre = max(pre, 0) + e;
                res = max(res, pre);
            }
            return res;
        }
    };